<template>
    <el-dialog
        :visible.sync="dialogVisible"
        size="60%"
        custom-class="selectin-pop-content"
        width="920px"
        append-to-body
        title="给予奖励"
        :before-close="handleClose">
        <div>
            <h3>您好，我们很高兴的通知您已入选{{ title }}{{scheduleTypeEnum[scheduleType]}}。具体安排如邮件下方，请于截止日期前上传{{scheduleTypeEnum[scheduleType]}}作品!</h3>
            <FormGroup :searchConfig="formConfig" ref="formParams" labelWidth="140px" labelPosition="right"/>
        </div>
        <div style="padding-left: 140px">
            <el-checkbox v-model="isSendEmail">发送邮箱通知参赛团队</el-checkbox>
        </div>
        <div style="margin-top: 30px; padding-left: 140px">
            <el-button @click="handleSendMsg">发送通知</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { giftConfig } from './../initData'
import { getNextScheduleByProjectId, batchUpdateStatus } from './../../api'
import FormGroup from '@/views/components/FormGroup';
export default {
    components: {
        FormGroup
    },
    data() {
        return {
            dialogVisible: false,
            formConfig: JSON.parse(JSON.stringify(giftConfig)),
            isSendMsg: false,
            isSendEmail: false,
            pageTitle: '入选通知',
            tableData: [],
            rowId: '',
            scheduleType: '',
            isBatch: false,
            scheduleTypeEnum: {
                1: '遴选',
                2: '初赛',
                3: '复赛',
                4: '决赛',
            },
            title: ''
        }
    },
    methods: {
        open({ rowId, scheduleType = null, title }) {
            this.scheduleType = scheduleType;
            this.title = title;
            this.dialogVisible = true;
            this.rowId = rowId;
        },
        // 发送通知
        async handleSendMsg() {
            const fromParams = this.$refs.formParams && await this.$refs.formParams.getParams();
            const params = {
                ...fromParams,
                isSendEmail: this.isSendEmail ? 1 : 0,
                ids: [this.rowId],
                type: 1, //	类型;0:撤销;1:入选;
            }
            delete params.date;
            delete params.time;
            const { code, msg, data } = await batchUpdateStatus(params);
            if (code === 0) {
                this.$message.success('发送成功');
                this.$emit('success');
                this.handleClose();
            } else {
                this.$message.error(msg)
            }
        },
        handleClose() {
            this.dialogVisible = false;
            this.isSendEmail = false;
            const newConfig = JSON.parse(JSON.stringify(giftConfig));
            this.formConfig = newConfig;
        },
        handleCalcel() {
            this.$emit('cancel');
        }
    }
}
</script>
<style lang="scss" scoped>
    
</style>